import axios from "axios";
import config from "src/config";

// 通过不同type获取对应数据
function nationalDataApi(type) {
  let url = config.api + "/country/" + type;
  if (config.isMock) {
    url += "?mock=true";
  }

  return new Promise((resolve, reject) => {
    axios
      .get(url)
      .then(res => {
        if (res.status === 200 && res.data.err === 0) {
          resolve({ name: res.data.name, nationalData: res.data.dataList });
        } else {
          reject(res);
        }
      })
      .catch(err => {
        reject(err);
      });
  });
}

export default nationalDataApi;
